package interfaz;

import org.uqbar.commons.model.UserException;
import org.uqbar.lacar.ui.model.Adapter;

import tablero.Coordenada;

public class NumeroEstrellasAdapter implements Adapter<Integer, String> {

	@Override
	public Class<Integer> getModelType() {
		return Integer.class;
	}

	@Override
	public Class<String> getViewType() {
		return String.class;
	}

	@Override
	public String modelToView(Integer x) {
			return String.valueOf(x);
	}

	@Override
	public Integer viewToModel(String x) {
		
		int num= validateInteger(x);
		if(num<1){
				throw new UserException("Numero de estrellas no valido. Por favor " +
						"ingrese un numero mayor a 0.");
			}
		
	
		return num;
	}
	
	private int validateInteger(String string) {
		try {
			return Integer.parseInt(string);	
		} catch (NumberFormatException e) {
			throw new UserException("Debe ingresar un número");
		}
	}

	

}
